//
//  MianTopButton.m
//  Medicare
//
//  Created by LYY on 2017/4/25.
//  Copyright © 2017年 medicare. All rights reserved.
//

#import "MainTopButton.h"
#import "IFMySchedulingPublicDefines.h"
@implementation MainTopButton  {
    CGSize _size;
    CGRect _frame;
}

- (void)setFrame:(CGRect)frame {
    [super setFrame:frame];
    _frame = frame;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    _frame = frame;
    return self;
}

- (void)setTitle:(nullable NSString *)title forState:(UIControlState)state {
    [super setTitle:title forState:state];
    _size = [title textSizeWithFont:CGSizeMake(CGRectGetWidth(_frame), CGRectGetHeight(_frame)) font:_textFont>0?_textFont:18];
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect {
    
    return CGRectMake(0, 0, CGRectGetWidth(_frame), CGRectGetHeight(_frame));
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    if (_size.width >= CGRectGetWidth(_frame)/2) {
        return CGRectMake(CGRectGetWidth(_frame)/2 + _size.width/2 + 5 + _imgLeftMargin, CGRectGetHeight(_frame)/2 - 7/2 + 1, 13, 7);
    }
    
    return CGRectMake(CGRectGetWidth(_frame)/2 + _size.width/2 + 5 + _imgLeftMargin, CGRectGetHeight(_frame)/2 - 7/2 + 1, 13, 7);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
